<template>
  <div>
    <div class="page_header">
      <div class="header_left">
        <el-divider direction="vertical" class="header_divider"></el-divider>
        <span class="header_title">知识库数量统计</span>
        <div class="header_refresh">
          <img src="../../../assets/images/home/refresh.png" class="header_refresh_img" alt="" @click="refreshClick" />
        </div>
      </div>
    </div>
    <div class="page_content">
      <div ref="commandstats" style="height: 260px" />
    </div>
  </div>
</template>

<script setup lang='ts'>
import homeIndexApi from '@/api/homeIndex/homeIndexApi';
import * as echarts from 'echarts';

const commandstats = ref();
const getDataList = () => {
  homeIndexApi.knowledgeEnterpriseFilesTreeAnalysisData().then((res: any) => {
    let groupName = res.data.map((item: any) => item.groupName);
    let aiSize = res.data.map((item: any) => item.aiSize);
    let noAiSize = res.data.map((item: any) => item.noAiSize);
    const commandstatsIntance = echarts.init(commandstats.value, 'macarons');
    commandstatsIntance.setOption({
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        }
      },
      legend: {},
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: {
        type: 'value',
        boundaryGap: [0, 0.01]
      },
      yAxis: {
        type: 'category',
        data: groupName
      },
      series: [
        {
          name: 'AI知识库数量',
          type: 'bar',
          data: aiSize,
          itemStyle: {
            color: '#ff9f43' 
          }
        },
        {
          name: '普通知识库数量',
          type: 'bar',
          data: noAiSize,
          itemStyle: {
            color: '#1989fa' 
          }
        }
      ]
    });
  })

}
const refreshClick = () => {

}
onMounted(() => {
  getDataList()
});
</script>
<style scoped lang='scss'>
.header_left {
  display: flex;
  align-items: center;

  .header_divider {
    width: 3px;
    border-radius: 2px;
    background-color: #2974f9;
  }

  .header_title {
    font-size: 16px;
    color: #2d2d2d;
    font-family: Source Han Sans CN;
    font-weight: 600;
  }

  .header_refresh {
    width: 18px;
    height: 18px;
    margin-left: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.3s;

    &:hover {
      background-color: #ececec;
    }

    .header_refresh_img {
      width: 12px;
      height: 12px;
    }
  }
}
</style>